import { getAttrInfoListApi } from '@/api/AttrApi'

export default {
  namespaced: true,
  state: {
    Category1Id: '',
    Category2Id: '',
    Category3Id: '',
    Category1List: [],
    Category2List: [],
    Category3List: [],
    AttrList: [],
    attrName: '',
    attrValueList: [],
    attrid: ''
  },
  mutations: {
    CHANGE3ID(state, val) {
      state.Category1Id = val.Category1Id
      state.Category2Id = val.Category2Id
      state.Category3Id = val.Category3Id
    },
    UPDATE_ATTRLIST(state, list) {
      state.AttrList = list
    },
    EDIT_ATTRINFO(state, info) {
      state.attrName = info.attrName
      state.attrValueList = info.attrValueList
      state.attrid = info.attrid
    }
  },
  actions: {
    ChangeId({ commit }, val) {
      commit('CHANGE3ID', val)
    },
    async GetAttrInfoList({ commit }) {
      const res = await getAttrInfoListApi(
        this.state.sortStore.Category1Id,
        this.state.sortStore.Category2Id,
        this.state.sortStore.Category3Id
      )
      if (res.code === 200) {
        commit('UPDATE_ATTRLIST', res.data)
      }
    },
    EditAttrInfo({ commit }, info) {
      commit('EDIT_ATTRINFO', info)
    }
  }
}
